﻿
using System;
using System.Collections.Generic;
using System.Text;
using sharpxbot.Core.Security.Traffic.Counters;
namespace sharpxbot.Core.Security.Traffic.Reports
{
    public class DayReport : ITrafficReport
    {
        public DateTime Date { get; set; }

        public HourReport[] HourReports { get; set; }

        public DayReport(DayCounters incoming, DayCounters outgoing)
        {
            if (incoming == null || outgoing == null)
                throw new NullReferenceException("Illegal null-reference parameters. DayReport ctor");

            if (incoming.Day != outgoing.Day)
                throw new ArgumentException("Inconsistent day in counters");

            Date = DateTime.Now.Date;

            HourReports = new HourReport[Constants.MaxHour];

            List<HourReport> buf = new List<HourReport>();
            for (int i = 0; i < Constants.MaxHour; ++i)
            {
                HourReport h = new HourReport(incoming.Hours[i], outgoing.Hours[i]);
                buf.Add(h);
            }
            HourReports = buf.ToArray();
        }

        #region ITrafficReport Members

        public string GetText()
        {
            StringBuilder sb = new StringBuilder();
            sb.AppendLine(String.Format("Daily report for {0}", Date));
            sb.AppendLine("===================");

            foreach (var h in HourReports)
            {
                sb.AppendLine(String.Format("{0}:00 Incoming [{1}]  Outgoing [{2}]", h.Date.Hour, h.IncomingBytes, h.OutgoingBytes));
            }
            return sb.ToString();
        }

        #endregion
    }
}
